package edu.yuhf.service;

import com.yuhf.dbutils.ParameterMap;
import com.yuhf.dbutils.TranscationManager;
import com.yuhf.dbutils.exception.TranscationException;
import com.yuhf.page.Page;
import edu.yuhf.dao.UserJdbcDaoImpl;
import edu.yuhf.dao.iface.UserDao;
import edu.yuhf.domain.User;
import edu.yuhf.service.iface.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {

    private UserDao userDao = UserJdbcDaoImpl.factory();
    @Override
    public void queryUserByPage(Page<User> page,ParameterMap parameterMap) {
        try {
            TranscationManager.beginTranscation();      //事务的开始
            userDao.queryByPage(page,parameterMap);
            userDao.getTotalRow(page,parameterMap);
            TranscationManager.commit();                //事务的正常结束
        } catch (TranscationException e) {
            TranscationManager.rollback();//事务的异常结束
            e.printStackTrace();
        }
    }

    @Override
    public List<User> queryUserAll() {
        return userDao.queryAll();
    }

    @Override
    public boolean queryUserByNameAndPwd(String userName, String password) {
        boolean flag = false;
        if(userDao.login(userName,password)==1){
            flag = true;
        }
        return flag;
    }
}
